define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    //edit_url: 'order/edit',
                    //del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'user_id', title: __('会员编号')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {
                            field: 'order_price',
                            title: __('Order_price'),
                            searchable: false,
                            operate: 'BETWEEN'
                        },
                        {
                            field: 'order_type_name',
                            searchable: false,
                            title: '订单类型'
                        },
                        {
                            field: 'is_agent_name',
                            searchable: false,
                            title: '代理单'
                        },
                        {
                            field: 'is_agent',
                            visible: false,
                            operate: '=',
                            title: '代理单',
                            searchList: {'1': '是', '2': '否'}
                        },
                        {field: 'transaction_id', title: '交易编号', operate: 'LIKE'},
                        {
                            field: 'status_name',
                            searchable: false,
                            title: '订单状态'
                        },
                        {
                            field: 'remark',
                            searchable: false,
                            title: '备注',
                            operate: 'LIKE'
                        },
                        {
                            field: 'a_time',
                            title: '下单时间',
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'p_time',
                            title: '付款时间',
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
